<div class="verify_mobile">
  <div class="vm m">
  	<input name="mobile" type="text"  id="mobile" class="input" placeholder="输入你的手机号">
  </div>
  <div class="vm c"><input name="verifyCode" type="text"  id="verifyCode" class="input" placeholder="输入验证码">
    <div class="sendcode font12" id="getVerifyCodeBtn">获取验证码</div>
  </div>
  <div class="btn font16" id="regBtnByMobile">验证</div>
  
</div>

<script>
    var timer, ountdownVal = 120;
    var ountdown = function () {
        ountdownVal--;
        if (ountdownVal <= 0) {
            clearInterval(timer);
            $('#getVerifyCodeBtn').html('获取验证码').removeClass('disabled').attr('disabled', 0);
        } else {
            $('#getVerifyCodeBtn').html('重发(' + ountdownVal + '秒)').addClass('disabled').attr('disabled', !0);
        }
    };

    $(function () {
        var regularMobileAuth = /^13[0-9]{9}$|14[0-9]{9}$|15[0-9]{9}$|18[0-9]{9}$|17[0-9]{9}$|16[0-9]{9}$|19[0-9]{9}$/;

        /* 获取验证码 */
        $("#getVerifyCodeBtn").click(function () {
            if ($(this).hasClass('disabled')) return false;
            var $mobile = $("#mobile");
            var mobile  = $mobile.val();

            if (mobile == '') {
                $mobile.focus();
                toast('请填写手机号！');
                return false;
            }
            if (!regularMobileAuth.test(mobile)) {
                $mobile.focus();
                toast('手机号码格式不正确！');
                return false;
            }
			$("input[name='verifyCode']").focus();
            $('#getVerifyCodeBtn').addClass('disabled');
            $.getJSON('{:U("Ajax/ajax_send_mobile_code")}', {mobile: mobile}, function (result) {
                if (result.code === 1) {
                    toast(result.msg, 1);
                    timer = setInterval(ountdown, 1000);
                } else {
					$('#getVerifyCodeBtn').removeClass('disabled');
                    toast(result.msg);
                }
            });
        });

        /* 注册手册号 */
        $("#regBtnByMobile").on('click', function () {
            if ($(this).hasClass('disabled')) return false;

            var $mobile = $("input[name='mobile']");
            var $code = $("input[name='verifyCode']");

            var mobile = $.trim($mobile.val());
            var code = $code.val();

            if (mobile == '') {
                $mobile.focus();
                toast('请填写手机号！');
                return false;
            }
            if (!regularMobileAuth.test(mobile)) {
                $mobile.focus();
                toast('手机号码格式不正确！');
                return false;
            }
            if (code == '') {
                $code.focus();
                toast('请填写验证码');
                return false;
            }

            $('#regBtnByMobile').html('验证中, 请稍等...').prop('disabled', !0).addClass('disabled');

            $.post('{:U("Ajax/ajax_verify_mobile_code")}', {mobile: mobile, code: code}, function (result) {
                if (result.code === 1) {
                    popout.hide();
                    var act = '{$act}';
                    eval(act)({:json_encode($params)});
                } else {
                    toast(result.msg);
                    $('#regBtnByMobile').html('验证').prop('disabled', 0).removeClass('disabled');
                }
            });
        });
    });
</script>


